/*
* jiyan
*/
package com.jiyan.errorcode.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.jiyan.core.entity.BeanRet;
import com.jiyan.core.entity.Page;
import com.jiyan.core.tools.redis.RedisUtils;
import com.jiyan.errorcode.entity.ErrorcodePool;
import com.jiyan.errorcode.service.ErrorcodePoolSV;

/**
* 错误码库 控制器
*
* @author jiyan
*/
@RestController
@RequestMapping("/errorcodePool")
@Slf4j
@Api(value = "错误码库控制器", description = "错误码库控制器")
public class ErrorcodePoolCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private ErrorcodePoolSV errorcodePoolSV;

    /**
    * 查询ErrorcodePool一个详情信息
    * @param id 
    * @param errorCode 错误码 由人为定义并制定出来指定一定场景模块的错误编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询ErrorcodePool一个详情信息", notes = "查询ErrorcodePool一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "query"),
        @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码",dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public ErrorcodePool load(java.lang.Long id,java.lang.String errorCode) {
        if(id==null){
        return null;
        }
        if(errorCode==null){
        return null;
        }
        ErrorcodePool errorcodePool = errorcodePoolSV.load(id,errorCode);
        log.info(JSON.toJSONString(errorcodePool));
        return errorcodePool;
    }


    /**
    * 根据条件id查询ErrorcodePool一个详情信息
    *
    * @param id 
    * @return BeanRet
    */
    @ApiOperation(value = "查询ErrorcodePool一个详情信息", notes = "查询ErrorcodePool一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public ErrorcodePool loadById(@PathVariable java.lang.Long id) {
        if(id==null){
           return null;
        }
        ErrorcodePool errorcodePool = errorcodePoolSV.loadById(id);
        log.info(JSON.toJSONString(errorcodePool));
        return errorcodePool;
    }
    /**
    * 根据条件errorCode查询ErrorcodePool一个详情信息
    *
    * @param errorCode 错误码 由人为定义并制定出来指定一定场景模块的错误编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询ErrorcodePool一个详情信息", notes = "查询ErrorcodePool一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/errorCode/{errorCode}")
    @ResponseBody
    public ErrorcodePool loadByErrorCode(@PathVariable java.lang.String errorCode) {
        if(errorCode==null){
           return null;
        }
        ErrorcodePool errorcodePool = errorcodePoolSV.loadByErrorCode(errorCode);
        log.info(JSON.toJSONString(errorcodePool));
        return errorcodePool;
    }


    /**
    * 查询ErrorcodePool信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询ErrorcodePool信息集合", notes = "查询ErrorcodePool信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<ErrorcodePool> list(@RequestBody @ApiIgnore ErrorcodePool errorcodePool,Integer curPage,Integer pageSize) {
        Page<ErrorcodePool> page=new Page<ErrorcodePool>(pageSize,curPage);
        List<ErrorcodePool> errorcodePools = errorcodePoolSV.list(errorcodePool,page.genRowStart(),page.getPageSize());
        int total = errorcodePoolSV.count(errorcodePool);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return errorcodePools;
    }


    /**
    * 查询ErrorcodePool信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询ErrorcodePool信息集合", notes = "查询ErrorcodePool信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<ErrorcodePool> listByPk(java.lang.Long id,java.lang.String errorCode,Integer curPage,Integer pageSize) {
        Page<ErrorcodePool> page=new Page<ErrorcodePool>(pageSize,curPage);
        List<ErrorcodePool> errorcodePools = errorcodePoolSV.list(id,errorCode, page.genRowStart(),page.getPageSize());
        int total = errorcodePoolSV.count(id,errorCode);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return errorcodePools;
    }

    /**
    * 统计ErrorcodePool信息数量根据主键
    *
    * @return 总条数
    */
    @ApiOperation(value = " 统计ErrorcodePool信息数量根据主键", notes = " 统计ErrorcodePool信息数量根据主键")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id,java.lang.String errorCode) {
        return errorcodePoolSV.count(id,errorCode);
    }

    /**
    * 统计ErrorcodePool信息数量
    *
    * @return 总条数
    */
    @ApiOperation(value = "统计ErrorcodePool信息数量", notes = "统计ErrorcodePool信息数量")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码", paramType = "query"),
    @ApiImplicitParam(name = "sceneCode", value = "场景编码", paramType = "query"),
    @ApiImplicitParam(name = "info", value = "文本对照,默认的错误信息提示", paramType = "query"),
    @ApiImplicitParam(name = "summary", value = "错误码说明解释错误码的作用和表达意思", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody ErrorcodePool errorcodePool) {
        return errorcodePoolSV.count(errorcodePool);
    }



    /**
    * 创建ErrorcodePool
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建ErrorcodePool", notes = "创建ErrorcodePool")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sceneCode", value = "场景编码", paramType = "query"),
        @ApiImplicitParam(name = "info", value = "文本对照,默认的错误信息提示", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "错误码说明解释错误码的作用和表达意思", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public ErrorcodePool build(@RequestBody @ApiIgnore ErrorcodePool errorcodePool) {
        errorcodePoolSV.save(errorcodePool);
        return errorcodePool;
    }


    /**
    * 修改ErrorcodePool
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改ErrorcodePool", notes = "修改ErrorcodePool")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码", paramType = "query"),
        @ApiImplicitParam(name = "sceneCode", value = "场景编码", paramType = "query"),
        @ApiImplicitParam(name = "info", value = "文本对照,默认的错误信息提示", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "错误码说明解释错误码的作用和表达意思", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public ErrorcodePool modify(@RequestBody @ApiIgnore ErrorcodePool errorcodePool) {
        errorcodePoolSV.modify(errorcodePool);
        return errorcodePool;
    }

    /**
    * 删除ErrorcodePool
    *
    * @return BeanRet
    */
    @ApiOperation(value = "删除ErrorcodePool", notes = "删除ErrorcodePool")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "errorCode", value = "错误码 由人为定义并制定出来指定一定场景模块的错误编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id,java.lang.String errorCode) {
        errorcodePoolSV.delete(id,errorCode);
        return BeanRet.create(true, "删除ErrorcodePool成功");
    }

}
